package com.adcc.ags.gms.gw.vo;

import com.adcc.ags.gms.core.entity.BaseEntity;
import com.adcc.ags.gms.core.vo.BaseVO;
import com.adcc.ags.gms.mq.vo.QueueVO;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;

/**
 * 队列信息视图
 */
public class QueueInfoVO extends BaseVO implements Comparable<QueueInfoVO>{

    // 队列名称
    private String name;

    // 生产者数
    private long producers;

    // 消费者数
    private long consumers;

    // 队列深度
    private long depth;

    // 队列最大深度
    private int maxDepth;

    // 进队列数
    private long enqueued;

    // 队列所属用户
    private String user = Strings.nullToEmpty("");

    // 是否堵报
    private boolean blocked;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public long getProducers() {
        return producers;
    }

    public void setProducers(long producers) {
        this.producers = producers;
    }

    public long getConsumers() {
        return consumers;
    }

    public void setConsumers(long consumers) {
        this.consumers = consumers;
    }

    public long getDepth() {
        return depth;
    }

    public void setDepth(long depth) {
        this.depth = depth;
    }

    public int getMaxDepth() {
        return maxDepth;
    }

    public void setMaxDepth(int maxDepth) {
        this.maxDepth = maxDepth;
    }

    public long getEnqueued() {
        return enqueued;
    }

    public void setEnqueued(long enqueued) {
        this.enqueued = enqueued;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public boolean isBlocked() {
        return blocked;
    }

    public void setBlocked(boolean blocked) {
        this.blocked = blocked;
    }

    /**
     * 构造函数
     */
    public QueueInfoVO(){

    }

    /**
     * 构造函数
     */
    public QueueInfoVO(QueueVO vo){
        if(vo != null){
            name = vo.getName();
            producers = vo.getProducers();
            consumers = vo.getConsumers();
            depth = vo.getDepth();
            maxDepth = vo.getMaxDepth();
            blocked = vo.isBlocked();
        }
    }

    @Override
    public BaseEntity toEntity() {
        return null;
    }

    @Override
    public String toJson() throws JsonProcessingException {
        return new ObjectMapper().writeValueAsString(this);
    }

    @Override
    public int compareTo(QueueInfoVO queueInfoVO) {
        if(Strings.isNullOrEmpty(user) && !Strings.isNullOrEmpty(queueInfoVO.getUser())){
            return 1;
        }else if(!Strings.isNullOrEmpty(user) && Strings.isNullOrEmpty(queueInfoVO.getUser())){
            return -1;
        }else {
            return user.compareTo(queueInfoVO.getUser());
        }
    }
}
